package com.zyh.system.dao.impl;

import com.zyh.system.dao.MovieDao;
import com.zyh.system.domain.Movie;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @Author zyh
 * @Date 2024/8/1 18:53
 * @Description
 */

public class MovieDaoImpl implements MovieDao {
    public static final Map<Movie, Integer> MOVIE_MAP = new HashMap<>();

    static {
        MOVIE_MAP.put(new Movie("警察故事", "动作片"), 8);
        MOVIE_MAP.put(new Movie("功夫熊猫", "动画片"), 6);
    }

    /**
     * 添加电影功能
     *
     * @param
     * @param
     * @return
     */
    @Override
    public boolean add(Map<Movie, Integer> map, Movie movie, Integer num) {
        map.put(movie, num);
        return true;
    }

    /**
     * 展示电影信息
     *
     * @param map
     */
    @Override
    public void showMovieInfo(Map<Movie, Integer> map) {
        Set<Movie> keySet = map.keySet();
        for (Movie key : keySet) {
            Integer value = map.get(key);
            System.out.println("电影名称：" + key.getMovieName() + "\n" + "电影类型：" + key.getMovieType() + "\n" + "电影人气：" + value);
            System.out.println();
        }
    }

    /**
     * 展示人气最高的电影
     *
     * @param map
     * @return
     */
    @Override
    public Map<Movie, Integer> showMax(Map<Movie, Integer> map) {
        int max = Integer.MIN_VALUE;
        Map<Movie, Integer> maxMovie = new HashMap<>();
        Collection<Integer> values = map.values();
        for (Integer value : values) {
            if (value > max) {
                max = value;
            }
        }
        Set<Movie> keySet = map.keySet();
        for (Movie key : keySet) {
            Integer value = map.get(key);
            if (value == max) {
                maxMovie.put(key, value);
            }
        }
        return maxMovie;

        /*Collection<Integer> values = map.values();
        for (Integer value : values) {
            if (value>max){
                max=value;
            }
        }
        Set<Movie> keySet = map.keySet();
        for (Movie key : keySet) {
            Integer value = map.get(key);
            if (value==max){
                newMap.put(key,value);
            }
        }*/
    }
}
